<?
require_once 'lang.php';
require_once($real_path . 'classes/form.php');
require_once($real_path . 'classes/generate_form.php');
require_once($real_path . 'functions/mail_functions.php');

ob_start('callback');

$gs_form		= 'sendmail';
$gs_action		= $_SERVER['REQUEST_URI'];
$gs_errorMsg	= '';

$url			= getValue('url', 'str', 'GET', '', 2);

// Get variable
$your_name		= getValue('your_name', 'str', 'POST', '');
$your_email		= getValue('your_email', 'str', 'POST', '');
$to_email		= getValue('to_email', 'str', 'POST', '');
$subject		= getValue('subject', 'str', 'POST', '');
$send_message	= getValue('send_message', 'str', 'POST', '');
$url			= getValue('url', 'str', 'POST', $url);

// Get action and security code variable
$security_code	= getValue('security_code', 'str', 'POST', '');
$action			= getValue('action', 'str', 'POST', '');
if ($action == 'execute')
{
	/*
	Call class form:
	1). Ten truong
	2). Ten form
	3). Kieu du lieu , 0 : string , 1 : kieu int, 2 : kieu email, 3 : kieu double, 4 : kieu hash password
	4). Noi luu giu data  0 : post, 1 : variable
	5). Gia tri mac dinh, neu require thi phai lon hon hoac bang default
	6). Du lieu nay co can thiet hay khong
	7). Loi dua ra man hinh
	8). Chi co duy nhat trong database
	9). Loi dua ra man hinh neu co duplicate
	*/
	$myform = new generate_form();
	// Add table insert data
	$myform->add('your_name', 'your_name', 0, 1, ' ', 1, '"' . tdt('Ten_cua_ban') . '" ' . tdt('buoc_phai_nhap'), 0, '');
	$myform->add('your_email', 'your_email', 2, 1, ' ', 1, '"' . tdt('Email_cua_ban') . '" ' . tdt('khong_phu_hop'), 0, '');
	$myform->add('to_email', 'to_email', 2, 1, ' ', 1, '"' . tdt('Email_gui_den') . '" ' . tdt('khong_phu_hop'), 0, '');

	// Check form data
	$gs_errorMsg .= $myform->checkdata();
	
	// Check security code
	if(check_session_security($security_code) == 0){
		$gs_errorMsg .= '&bull; "' . tdt('Ma_so_an_toan') . '" ' . tdt('khong_phu_hop') . '<br />';
	}
	
	if($gs_errorMsg == ''){
		
		// Gửi mail thông báo cho admin biết
		$message = $your_name . ' (' . $your_email . ') ' . tdt('Gui_cho_ban_mot_link_gioi_thieu') . ":\n";
		$message.= base64_decode($url) . '\n\n';
		$message.= tdt('Voi_loi_nhan') . ': ' . mb_substr($send_message, 0, 300, "UTF-8") . '\n';
		//echo nl2br($message) . '<br />';
		
		$to      = $to_email;
		$subject = "[GTK] " . $subject;
		$headers = "From: info@" . str_replace("www.", '', $_SERVER['SERVER_NAME']);
		sendmail($to, $subject, $message, $headers, $con_sendmail_method, $con_smtp_username, $con_smtp_password, $real_path . 'classes/');
		
		// Close window
		echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">';
		echo '<script type="text/javascript">alert("' . tdt('Ban_da_gui_thanh_cong') . '"); window.close();</script>';
		
	}// End if($gs_errorMsg == '')
	
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="google-site-verification" content="GHWz12dNXVEPsA2t_G9nkEUCRd7Mwhz7o9xnLz14BM8">
<title>Gửi cho bạn bè</title>
<style type="text/css" media="all">@import "<?=$con_root_path?>css/GSmain.css";</style>
<style type="text/css">
body{
	background:#00648b;
}
.form_button{
	font-family:Arial, Helvetica;
	font-size:11px;
	font-weight:normal;
	width:70px;
}
.form_errorMsg{
	color:#FFFF00;
}
.form_name{
	color:#FFFFFF;
}
.form_text{
	font-size:11px;
	color:#FFFFFF;
}
.form_text_note{
	color:#DEDEDE;
	text-align:left;
}
</style>
</head>
<body style="margin:10px">
<div align="center">
<?
$form = new form();
$form->add_javascript($con_root_path . 'js/library.php', '');
$form->create_form($gs_form, $gs_action, 'POST', '', '');
$form->create_table(0, 0, '');
echo $form->text_note(str_replace('*', '<span class="form_asterisk">*</span>', tdt('Nhung_o_co_dau_sao_(*)_la_bat_buoc_phai_nhap')));
echo $form->errorMsg($gs_errorMsg);
echo $form->text(tdt('Ten_cua_ban'), 'your_name', 'your_name', $your_name, tdt('Ten_cua_ban'), 0, 200, '', 255, '', '', '');
echo $form->text(tdt('Email_cua_ban'), 'your_email', 'your_email', $your_email, tdt('Email_cua_ban'), 0, 200, '', 255, '', '', '');
echo $form->text(tdt('Gui_den_(To_email)'), 'to_email', 'to_email', $to_email, tdt('Email_gui_den'), 3, 200, '', 255, '', '', '');
echo $form->text(tdt('Tieu_de_(Subject)'), 'subject', 'subject', $subject, tdt('Tieu_de_(Subject)'), 0, 200, '', 255, '', '', '');
echo $form->textarea(tdt('Thong_diep_(Message)'), 'send_message', 'send_message', $send_message, tdt('Thong_diep_(Message)'), 0, 250, 150, '', '', '');
$_SESSION['session_security_code'] = generate_security_code();
echo $form->text(tdt('Ma_so_an_toan'), 'security_code', 'security_code', '', tdt('Ma_so_an_toan'), 2, 65, '', 4, '', '', '<img align="absmiddle" hspace="5" src="' . $con_root_path . 'security_code.php?' . random() . '" />');
echo $form->button('submit' . $form->ec . 'reset', 'submit' . $form->ec . 'reset', 'submit' . $form->ec . 'reset', tdt('Gui_di') . $form->ec . tdt('Lam_lai'), tdt('Gui_di') . $form->ec . tdt('Lam_lai'), $form->ec, '');
echo $form->hidden('action', 'action', 'execute', '');
echo $form->hidden('url', 'url', $url, '');
$form->close_table();
$form->close_form();
unset($form);
?>
</div>
</body>
</html>
<script type="text/javascript">self.moveTo((screen.width-document.body.clientWidth)/2, (screen.height-document.body.clientHeight)/2);</script>
<?
ob_end_flush();
?>